// pages/index/starDetails/starDetails.js
import config from "../../../utils/config.js";
Page({

  /**
   * Page initial data
   */
  data: {
    contentList: [],
    title: "",
    subtitle: ""
  },
  // splice content
  spliceContent(str) {
    var arr = str.split('"');
    var newArr = [];
    // console.log(arr);
    for (var i = 0; i < arr.length; i++) {
      if (arr[i].length >= 20) {
        newArr.push(arr[i]);
      }
    }
    this.setData({
      contentList: newArr
    });
  },
  // change img 
  change(e) {
    console.log(e.detail.current);
  },

  /**
   * Lifecycle function--Called when page load
   */
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: config.topicDetails,
      data: { id: options.sid},
      success: function(res) {
        // console.log(res.data.data);
        that.setData({
          title: res.data.data.title,
          subtitle: res.data.data.subtitle
        });
        that.spliceContent(res.data.data.content);
      }
    })
  },

  /**
   * Lifecycle function--Called when page is initially rendered
   */
  onReady: function () {

  },

  /**
   * Lifecycle function--Called when page show
   */
  onShow: function () {

  },

  /**
   * Lifecycle function--Called when page hide
   */
  onHide: function () {

  },

  /**
   * Lifecycle function--Called when page unload
   */
  onUnload: function () {

  },

  /**
   * Page event handler function--Called when user drop down
   */
  onPullDownRefresh: function () {

  },

  /**
   * Called when page reach bottom
   */
  onReachBottom: function () {

  },

  /**
   * Called when user click on the top right corner to share
   */
  onShareAppMessage: function () {

  }
})